package com.nkdx.ws.mapper;

import com.nkdx.ws.dto.UserDto;
import com.nkdx.ws.eto.UserEto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 *   用户表 mapper
 *
 * @author ZZW
 * @date 2022/3/2 3:34 下午
 * @param
 * @return
 */

@Repository
public interface UserMapper {

    /**
     * 根据 用户名 查询 用户
     * @param name
     * @return
     */
    @Select("SELECT id,`name`,`password`,nick_name AS nickName,email,phone,`desc`,`status`,create_time AS createTime,update_time AS updateTime,last_login_time AS lastLoginTime,user_type AS userType " +
            "FROM ws_user " +
            "WHERE name = #{name} ")
    public UserDto findUserByName(String name);

    /**
     *
     *  查询 所有用户
     * @author ZZW
     * @date 2022/3/3 4:52 下午
     * @param
     * @return
     */
    @Select("SELECT id,`name`,`password`,nick_name AS nickName,email,phone,`desc`,`status`,create_time AS createTime,update_time AS updateTime,last_login_time AS lastLoginTime,user_type AS userType FROM ws_user ")
    public List<UserDto> findAllUsers();

    /**
     *   修改 用户最后登录时间
     * @author ZZW
     * @date 2022/3/3 7:46 下午
     * @param
     * @return
     */
    @Update("update ws_user set last_login_time = #{lastLoginTime} where id = #{id}")
    public void updateUserLastLoginTime(@Param("id") Integer id, @Param("lastLoginTime") Date lastLoginTime);

    @Select("SELECT id,`name`,`password`,nick_name AS nickName,email,phone,`desc`,`status`,create_time AS createTime,update_time AS updateTime,last_login_time AS lastLoginTime,user_type as userType" +
            " FROM ws_user WHERE id = #{id}")
    public UserDto findUserById(Integer id);

    void update(UserEto eto);

    int insert(UserEto record);

    int insertSelective(UserEto record);

}
